package com.bjqg.bjqg01.bjqg.activity.longrange.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.bjqg.bjqg01.bjqg.R;
import com.bjqg.bjqg01.bjqg.activity.BaseActivity;
import com.bjqg.bjqg01.bjqg.activity.address.activity.AddressManagerActivity;
import com.bjqg.bjqg01.bjqg.activity.longrange.adapter.ImageItem;
import com.bjqg.bjqg01.bjqg.activity.longrange.bean.AddressEventBean;
import com.bjqg.bjqg01.bjqg.activity.longrange.bean.ConcreteBean;
import com.bjqg.bjqg01.bjqg.activity.longrange.bean.FsBean;
import com.bjqg.bjqg01.bjqg.activity.longrange.bean.MultipleBean;
import com.bjqg.bjqg01.bjqg.activity.longrange.dialog.BottomMenuDialog;
import com.bjqg.bjqg01.bjqg.activity.longrange.dialog.JcDialog;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.CydwBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.CyrBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.GcmcBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.JzdwBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.JzrBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.SgbwBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.WtdwBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.WtrBeanUtils;
import com.bjqg.bjqg01.bjqg.activity.longrange.utils.WtrPhoneBeanUtils;
import com.bjqg.bjqg01.bjqg.ui.pickview.OptionsPickerView;
import com.bjqg.bjqg01.bjqg.ui.pickview.TimePickerView;
import com.bjqg.bjqg01.bjqg.ui.pickview.listener.CustomListener;
import com.bjqg.bjqg01.bjqg.utils.Bimp;
import com.bjqg.bjqg01.bjqg.utils.BitmapUtils;
import com.bjqg.bjqg01.bjqg.utils.GreendaoUtils;
import com.jph.takephoto.app.TakePhoto;
import com.jph.takephoto.app.TakePhotoActivity;
import com.jph.takephoto.compress.CompressConfig;
import com.jph.takephoto.model.TImage;
import com.jph.takephoto.model.TResult;
import com.jph.takephoto.model.TakePhotoOptions;
import com.zhy.autolayout.AutoLinearLayout;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by bjqg01 on 2018/9/6.
 */

public class ConcreteActivity extends TakePhotoActivity {

    //砼抗压
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.tv_top_title_drawer)
    TextView tvTopTitleDrawer;
    @BindView(R.id.tv_search_top_drawer)
    TextView tvSearchTopDrawer;
    @BindView(R.id.commissioned_tv_jllb)
    TextView TvJllb;
    @BindView(R.id.commissioned_et_wtdw)
    AutoCompleteTextView EtWtdw;
    @BindView(R.id.commissioned_et_wtr)
    AutoCompleteTextView EtWtr;
    @BindView(R.id.commissioned_et_wtrdh)
    AutoCompleteTextView EtWtrdh;
    @BindView(R.id.commissioned_et_gcmc)
    AutoCompleteTextView EtGcmc;
    @BindView(R.id.commissioned_et_sgbw)
    AutoCompleteTextView EtSgbw;
    @BindView(R.id.et_dbsl)
    EditText etDbsl;
    @BindView(R.id.commissioned_tv_dj)
    TextView TvDj;
    @BindView(R.id.et_sqcc)
    TextView etSqcc;
    @BindView(R.id.commissioned_al_djfather)
    AutoLinearLayout AlDjfather;
    @BindView(R.id.commissioned_tv_jc)
    TextView TvJc;
    @BindView(R.id.et_ypmc)
    TextView etYpmc;
    @BindView(R.id.commissioned_al_jcfather)
    AutoLinearLayout AlJcfather;
    @BindView(R.id.tv_dj)
    TextView tvDj;
    @BindView(R.id.et_yhtj)
    TextView etYhtj;
    @BindView(R.id.commissioned_et_dbsl)
    EditText EtDbsl;

    @BindView(R.id.et_yjbz)
    EditText etYjbz;
    @BindView(R.id.et_cxrq)
    TextView etCxrq;
    @BindView(R.id.et_ql)
    EditText etQl;
    @BindView(R.id.et_yqsyrq)
    TextView etYqsyrq;
    @BindView(R.id.et_phblbl)
    EditText etPhblbl;
    @BindView(R.id.et_jcxm)
    TextView etJcxm;
    @BindView(R.id.et_lysl)
    EditText etLysl;
    @BindView(R.id.et_zlzms)
    EditText etZlzms;
    @BindView(R.id.et_ypcz)
    TextView etYpcz;
    @BindView(R.id.commissioned_et_zj)
    TextView EtZj;
    @BindView(R.id.et_sn)
    EditText etSn;
    @BindView(R.id.et_sha)
    EditText etSha;
    @BindView(R.id.et_shi)
    EditText etShi;
    @BindView(R.id.et_shui)
    EditText etShui;
    @BindView(R.id.et_wjj1)
    EditText etWjj1;
    @BindView(R.id.et_wjj2)
    EditText etWjj2;
    @BindView(R.id.et_wjj3)
    EditText etWjj3;
    @BindView(R.id.et_wjj4)
    EditText etWjj4;
    @BindView(R.id.et_chl1)
    EditText etChl1;
    @BindView(R.id.et_chl2)
    EditText etChl2;
    @BindView(R.id.et_chl3)
    EditText etChl3;
    @BindView(R.id.et_chl4)
    EditText etChl4;
    @BindView(R.id.et_qt1)
    EditText etQt1;
    @BindView(R.id.et_qt2)
    EditText etQt2;
    @BindView(R.id.ll_mfyl_father)
    AutoLinearLayout llMfylFather;
    @BindView(R.id.et_pan_sn)
    EditText etPanSn;
    @BindView(R.id.et_pan_sha)
    EditText etPanSha;
    @BindView(R.id.et_pan_shi)
    EditText etPanShi;
    @BindView(R.id.et_pan_shui)
    EditText etPanShui;
    @BindView(R.id.et_pan_wjj1)
    EditText etPanWjj1;
    @BindView(R.id.et_pan_wjj2)
    EditText etPanWjj2;
    @BindView(R.id.et_pan_wjj3)
    EditText etPanWjj3;
    @BindView(R.id.et_pan_wjj4)
    EditText etPanWjj4;
    @BindView(R.id.et_pan_chl1)
    EditText etPanChl1;
    @BindView(R.id.et_pan_chl2)
    EditText etPanChl2;
    @BindView(R.id.et_pan_chl3)
    EditText etPanChl3;
    @BindView(R.id.et_pan_chl4)
    EditText etPanChl4;
    @BindView(R.id.et_pan_qt1)
    EditText etPanQt1;
    @BindView(R.id.et_pan_qt2)
    EditText etPanQt2;
    @BindView(R.id.ll_mpyl_father)
    AutoLinearLayout llMpylFather;
    @BindView(R.id.et_dbsl_wjj)
    EditText etDbslWjj;
    @BindView(R.id.et_scdw_wjj)
    EditText etScdwWjj;
    @BindView(R.id.et_sb_wjj)
    EditText etSbWjj;
    @BindView(R.id.et_ggxh_wjj)
    EditText etGgxhWjj;
    @BindView(R.id.et_ypmc_wjj)
    EditText etYpmcWjj;
    @BindView(R.id.et_cl_wjj)
    EditText etClWjj;
    @BindView(R.id.et_zlzms_wjj)
    EditText etZlzmsWjj;
    @BindView(R.id.et_jcxm_wjj)
    TextView etJcxmWjj;
    @BindView(R.id.et_lysl_wjj)
    EditText etLyslWjj;
    @BindView(R.id.et_zj_wjj)
    EditText etZjWjj;
    @BindView(R.id.ll_wjj_father)
    AutoLinearLayout llWjjFather;
    @BindView(R.id.commissioned_et_cydw)
    AutoCompleteTextView EtCydw;

    @BindView(R.id.commissioned_et_cyr)
    AutoCompleteTextView EtCyr;

    @BindView(R.id.commissioned_et_jzdw)
    AutoCompleteTextView EtJzdw;
    @BindView(R.id.commissioned_et_jzr)
    AutoCompleteTextView EtJzr;

    @BindView(R.id.ll_jzqy)
    AutoLinearLayout llJzqy;
    @BindView(R.id.et_bz)
    EditText etBz;
    @BindView(R.id.commissioned_rb_zq)
    RadioButton RbZq;
    @BindView(R.id.commissioned_rb_yj)
    RadioButton RbYj;
    @BindView(R.id.commissioned_rg)
    RadioGroup Rg;
    @BindView(R.id.commissioned_et_ddh)
    EditText EtDdh;
    @BindView(R.id.ll_ddh)
    AutoLinearLayout llDdh;
    @BindView(R.id.commissioned_rb_bg_zq)
    RadioButton RbBgZq;
    @BindView(R.id.commissioned_rb_bg_yj)
    RadioButton RbBgYj;
    @BindView(R.id.commissioned_rg_bg)
    RadioGroup RgBg;
    @BindView(R.id.commissioned_tv_xzdz)
    TextView TvXzdz;
    @BindView(R.id.commissioned_tv_xm)
    TextView TvXm;
    @BindView(R.id.commissioned_tv_lxdh)
    TextView TvLxdh;
    @BindView(R.id.commissioned_tv_yjdz)
    TextView TvYjdz;
    @BindView(R.id.ll_yj_father)
    AutoLinearLayout llYjFather;
    @BindView(R.id.project_information_btn_send)
    Button BtnSend;

    //砼抗渗
    @BindView(R.id.ll_tky_father)
    AutoLinearLayout llTkyFather;
    @BindView(R.id.et_tks_dbsl)
    EditText etTksDbsl;
    @BindView(R.id.et_tks_cc)
    EditText etTksCc;
    @BindView(R.id.et_tks_yqsyrq)
    TextView etTksYqsyrq;
    @BindView(R.id.et_tks_qddj)
    TextView etTksQddj;
    @BindView(R.id.et_tks_ksdj)
    TextView etTksKsdj;
    @BindView(R.id.et_tks_kddj)
    EditText etTksKddj;
    @BindView(R.id.et_tks_yjbz)
    EditText etTksYjbz;
    @BindView(R.id.et_tks_cxrq)
    TextView etTksCxrq;
    @BindView(R.id.et_tks_ql)
    EditText etTksQl;
    @BindView(R.id.et_tks_phbbh)
    EditText etTksPhbbh;
    @BindView(R.id.et_tks_zlzms)
    EditText etTksZlzms;
    @BindView(R.id.et_tks_lysl)
    EditText etTksLysl;
    @BindView(R.id.et_tks_jcxm)
    TextView etTksJcxm;
    @BindView(R.id.ll_tks_father)
    AutoLinearLayout llTksFather;


    //砼抗折
    @BindView(R.id.et_tkz_yjbz)
    EditText etTkzYjbz;
    @BindView(R.id.et_tkz_skcc)
    TextView etTkzSkcc;
    @BindView(R.id.et_tkz_qddj)
    TextView etTkzQddj;
    @BindView(R.id.et_tkz_dbsl)
    EditText etTkzDbsl;
    @BindView(R.id.et_tkz_yhtj)
    TextView etTkzYhtj;
    @BindView(R.id.et_tkz_cxrq)
    TextView etTkzCxrq;
    @BindView(R.id.et_tkz_ql)
    EditText etTkzQl;
    @BindView(R.id.et_tkz_yqsyrq)
    TextView etTkzYqsyrq;
    @BindView(R.id.et_tkz_zlzms)
    EditText etTkzZlzms;
    @BindView(R.id.et_tkz_lysl)
    EditText etTkzLysl;
    @BindView(R.id.et_tkz_jcxm)
    TextView etTkzJcxm;
    @BindView(R.id.ll_tkz_father)
    AutoLinearLayout llTkzFather;

    //砼抗冻
    @BindView(R.id.et_tkd_qddj)
    TextView etTkdQddj;
    @BindView(R.id.et_tkd_yhtj)
    TextView etTkdYhtj;
    @BindView(R.id.et_tkd_ksdj)
    TextView etTkdKsdj;
    @BindView(R.id.et_tkd_kddj)
    TextView etTkdKddj;
    @BindView(R.id.et_tkd_cxrq)
    TextView etTkdCxrq;
    @BindView(R.id.et_tkd_ql)
    TextView etTkdQl;
    @BindView(R.id.et_tkd_yqsyrq)
    TextView etTkdYqsyrq;
    @BindView(R.id.et_tkd_phbbh)
    EditText etTkdPhbbh;
    @BindView(R.id.et_tkd_yjbz)
    EditText etTkdYjbz;
    @BindView(R.id.et_tkd_skcc)
    TextView etTkdSkcc;
    @BindView(R.id.et_tkd_dbsl)
    TextView etTkdDbsl;
    @BindView(R.id.et_tkd_sybh)
    TextView etTkdSybh;
    @BindView(R.id.et_tkd_lysl)
    EditText etTkdLysl;
    @BindView(R.id.et_tkd_zlzms)
    EditText etTkdZlzms;
    @BindView(R.id.et_tkd_jcxm)
    TextView etTkdJcxm;
    @BindView(R.id.ll_tkd_father)
    AutoLinearLayout llTkdFather;

    //砂浆抗压
    @BindView(R.id.et_sjky_yjbz)
    EditText etSjkyYjbz;
    @BindView(R.id.et_sjky_skcc)
    TextView etSjkySkcc;
    @BindView(R.id.et_sjky_yhtj)
    TextView etSjkyYhtj;
    @BindView(R.id.et_sjky_qddj)
    TextView etSjkyQddj;
    @BindView(R.id.et_sjky_cxrq)
    TextView etSjkyCxrq;
    @BindView(R.id.et_sjky_ql)
    EditText etSjkyQl;
    @BindView(R.id.et_sjky_yqsyrq)
    TextView etSjkyYqsyrq;
    @BindView(R.id.et_sjky_sjzl)
    TextView etSjkySjzl;
    @BindView(R.id.et_sjky_phbbh)
    TextView etSjkyPhbbh;
    @BindView(R.id.et_sjky_zlzms)
    EditText etSjkyZlzms;
    @BindView(R.id.et_sjky_lysl)
    EditText etSjkyLysl;
    @BindView(R.id.et_sjky_jcxm)
    TextView etSjkyJcxm;
    @BindView(R.id.ll_sjky_father)
    AutoLinearLayout llSjkyFather;

    //预拌砂浆
    @BindView(R.id.et_ybsj_dbsl)
    EditText etYbsjDbsl;
    @BindView(R.id.et_ybsj_scrq)
    TextView etYbsjScrq;
    @BindView(R.id.et_ybsj_sjpz)
    TextView etYbsjSjpz;
    @BindView(R.id.et_ybsj_sjzl)
    TextView etYbsjSjzl;
    @BindView(R.id.et_ybsj_qddj)
    TextView etYbsjQddj;
    @BindView(R.id.et_ybsj_yjbz)
    EditText etYbsjYjbz;
    @BindView(R.id.et_ybsj_sccj)
    EditText etYbsjSccj;
    @BindView(R.id.et_ybsj_zlzs)
    EditText etYbsjZlzs;
    @BindView(R.id.et_ybsj_lysl)
    TextView etYbsjLysl;
    @BindView(R.id.et_ybsj_jcxm)
    TextView etYbsjJcxm;
    @BindView(R.id.ll_ybsj_father)
    AutoLinearLayout llYbsjFather;
    @BindView(R.id.et_tks_zj)
    EditText etTksZj;
    @BindView(R.id.et_tkz_zj)
    TextView etTkzZj;
    @BindView(R.id.et_tkd_zj)
    TextView etTkdZj;
    @BindView(R.id.et_sjky_zj)
    TextView etSjkyZj;
    @BindView(R.id.et_ybsj_zj)
    TextView etYbsjZj;
    @BindView(R.id.tv_ywtbh)
    TextView tvYwtbh;
    @BindView(R.id.et_bgfs)
    TextView etBgfs;
    @BindView(R.id.iv_wtd)
    ImageView ivWtd;


    List<ConcreteBean> listconcre = new ArrayList<>();
    List<String> name = new ArrayList<>();
    OptionsPickerView pvFenLei, pvFs;
    TimePickerView pvTime1;
    private SimpleDateFormat format;
    private String PHOTO_FILE_NAME;
    private StringBuffer sb = new StringBuffer();
    private BottomMenuDialog mButtomMenuDialog;
    private File dir;
    private boolean isFirstIn = true;//记录是否是刚进入页面
    JcDialog.Builde builde;
    List<FsBean> list1 = new ArrayList<>();
    List<String> lvname = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_concrete);
        ButterKnife.bind(this);
        EventBus.getDefault().register(this);
        initdata();
        initfelei();
        initcxtime();
        initfs();
    }

    private void initdata() {

        dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/PhotoPickTemp");
        if (!dir.exists()) {
            dir.mkdirs();
        }

        format = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss", Locale.CHINA);

        tvTopTitleDrawer.setText(getIntent().getStringExtra("name"));
        tvSearchTopDrawer.setVisibility(View.INVISIBLE);
        TvJllb.setText("砼抗压");
        listconcre.add(new ConcreteBean("砼抗压", "1"));
        listconcre.add(new ConcreteBean("砼抗渗", "2"));
        listconcre.add(new ConcreteBean("砼抗折", "3"));
        listconcre.add(new ConcreteBean("砼抗冻", "4"));
        listconcre.add(new ConcreteBean("砂浆抗压", "5"));
        listconcre.add(new ConcreteBean("预拌砂浆", "6"));
        listconcre.add(new ConcreteBean("外加剂", "7"));

        for (int i = 0; i < listconcre.size(); i++) {
            name.add(listconcre.get(i).getName());
        }


        list1.add(new FsBean("1份  ¥0", "1"));
        list1.add(new FsBean("2份  ¥10", "2"));
        list1.add(new FsBean("3份  ¥20", "3"));
        list1.add(new FsBean("4份  ¥30", "4"));
        list1.add(new FsBean("5份  ¥40", "5"));
        list1.add(new FsBean("6份  ¥50", "6"));
        list1.add(new FsBean("7份  ¥60", "7"));
        list1.add(new FsBean("8份  ¥70", "8"));
        list1.add(new FsBean("9份  ¥80", "9"));
        list1.add(new FsBean("10份  ¥90", "10"));

        for (int i = 0; i < list1.size(); i++) {
            lvname.add(list1.get(i).getName());
        }


        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, WtdwBeanUtils.listEName(GreendaoUtils.getDaoSession(ConcreteActivity.this, "wtdw.db")));
        EtWtdw.setAdapter(adapter);


        //委托人
        ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, WtrBeanUtils.listEName(GreendaoUtils.getDaoSession(ConcreteActivity.this, "wtr.db")));
        EtWtr.setAdapter(adapter2);

        //委托人电话
        ArrayAdapter<String> adapter3 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, WtrPhoneBeanUtils.listEName(GreendaoUtils.getDaoSession(ConcreteActivity.this, "wtrdh.db")));
        EtWtrdh.setAdapter(adapter3);

        //工程名称
        ArrayAdapter<String> adapter4 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, GcmcBeanUtils.listEName(GreendaoUtils.getDaoSession(ConcreteActivity.this, "gcmc.db")));
        EtGcmc.setAdapter(adapter4);

        //施工部位
        ArrayAdapter<String> adapter5 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, SgbwBeanUtils.listEName(GreendaoUtils.getDaoSession(ConcreteActivity.this, "sgbw.db")));
        EtSgbw.setAdapter(adapter5);

        //抽样单位
        ArrayAdapter<String> adapter6 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, CydwBeanUtils.listEName(GreendaoUtils.getDaoSession(ConcreteActivity.this, "cydw.db")));
        EtCydw.setAdapter(adapter6);

        //抽样人
        ArrayAdapter<String> adapter7 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, CyrBeanUtils.listEName(GreendaoUtils.getDaoSession(ConcreteActivity.this, "cyr.db")));
        EtCyr.setAdapter(adapter7);

        //见证单位
        ArrayAdapter<String> adapter8 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, JzdwBeanUtils.listEName(GreendaoUtils.getDaoSession(ConcreteActivity.this, "jzdw.db")));
        EtJzdw.setAdapter(adapter8);

        //见证人
        ArrayAdapter<String> adapter9 = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, JzrBeanUtils.listEName(GreendaoUtils.getDaoSession(ConcreteActivity.this, "jzr.db")));
        EtJzr.setAdapter(adapter9);

        Callphone();
    }

    @OnClick({R.id.back, R.id.commissioned_tv_jllb, R.id.project_information_btn_send, R.id.iv_wtd,
            R.id.commissioned_rb_zq, R.id.commissioned_rb_yj, R.id.commissioned_rb_bg_zq, R.id.commissioned_rb_bg_yj,
            R.id.commissioned_tv_xzdz, R.id.et_cxrq, R.id.et_yqsyrq, R.id.et_tks_yqsyrq, R.id.et_tks_cxrq, R.id.et_tkz_cxrq,
            R.id.et_tkz_yqsyrq, R.id.et_tkd_cxrq, R.id.et_tkd_yqsyrq, R.id.et_sjky_cxrq, R.id.et_sjky_yqsyrq, R.id.et_ybsj_scrq,
            R.id.et_jcxm, R.id.et_tks_jcxm, R.id.et_tkz_jcxm, R.id.et_tkd_jcxm, R.id.et_sjky_jcxm, R.id.et_ybsj_jcxm,
            R.id.et_jcxm_wjj,R.id.et_bgfs})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.commissioned_tv_jllb:
                pvFenLei.show();
                break;
            case R.id.project_information_btn_send:
                Toast.makeText(this, "保存", Toast.LENGTH_SHORT).show();

                WtdwBeanUtils.insertdata(EtWtdw.getText().toString());
                WtrBeanUtils.insertdata(EtWtr.getText().toString());
                WtrPhoneBeanUtils.insertdata(EtWtrdh.getText().toString());
                SgbwBeanUtils.insertdata(EtSgbw.getText().toString());
                GcmcBeanUtils.insertdata(EtGcmc.getText().toString());
                CydwBeanUtils.insertdata(EtCydw.getText().toString());
                CyrBeanUtils.insertdata(EtCyr.getText().toString());
                JzdwBeanUtils.insertdata(EtJzdw.getText().toString());
                JzrBeanUtils.insertdata(EtJzr.getText().toString());

                finish();
                break;
            case R.id.commissioned_rb_zq://样品送达方式 自送
                llDdh.setVisibility(View.GONE);
                EtDdh.setText("");
                break;
            case R.id.commissioned_rb_yj://邮寄
                llDdh.setVisibility(View.VISIBLE);
                break;
            case R.id.commissioned_rb_bg_zq://报告发放方式 自取
                TvXzdz.setVisibility(View.GONE);
                llYjFather.setVisibility(View.GONE);
                TvXm.setText("");
                TvLxdh.setText("");
                TvYjdz.setText("");
                break;
            case R.id.commissioned_rb_bg_yj:
                TvXzdz.setVisibility(View.VISIBLE);
                break;
            case R.id.commissioned_tv_xzdz://选择地址
                Intent toaddress = new Intent(ConcreteActivity.this, AddressManagerActivity.class);
                toaddress.putExtra("finish", "yes");
                startActivity(toaddress);
                break;
            case R.id.et_cxrq:
                pvTime1.show(etCxrq);
                break;
            case R.id.et_yqsyrq:
                pvTime1.show(etYqsyrq);
                break;
            case R.id.et_tks_yqsyrq:
                pvTime1.show(etTksYqsyrq);
                break;
            case R.id.et_tks_cxrq:
                pvTime1.show(etTksCxrq);
                break;
            case R.id.et_tkz_cxrq:
                pvTime1.show(etTkzCxrq);
                break;
            case R.id.et_tkz_yqsyrq:
                pvTime1.show(etTkzYqsyrq);
                break;
            case R.id.et_tkd_cxrq:
                pvTime1.show(etTkdCxrq);
                break;
            case R.id.et_tkd_yqsyrq:
                pvTime1.show(etTkdYqsyrq);
                break;
            case R.id.et_sjky_cxrq:
                pvTime1.show(etSjkyCxrq);
                break;
            case R.id.et_sjky_yqsyrq:
                pvTime1.show(etSjkyYqsyrq);
                break;
            case R.id.et_ybsj_scrq:
                pvTime1.show(etYbsjScrq);
                break;
            case R.id.et_jcxm:

                if (etYjbz.getText().toString().equals("")) {
                    builde.create().show();
                } else {
                    Intent tojcxm = new Intent(this, ChoiceActivity.class);
                    startActivity(tojcxm);
                    sb.setLength(0);
                }
                break;
            case R.id.et_tks_jcxm:
                if (etTksYjbz.getText().toString().equals("")) {
                    builde.create().show();
                } else {
                    Intent tojcxm = new Intent(this, ChoiceActivity.class);
                    startActivity(tojcxm);
                    sb.setLength(0);
                }

                break;
            case R.id.et_tkz_jcxm:
                if (etTkzYjbz.getText().toString().equals("")) {
                    builde.create().show();
                } else {
                    Intent tojcxm = new Intent(this, ChoiceActivity.class);
                    startActivity(tojcxm);
                    sb.setLength(0);
                }
                break;
            case R.id.et_tkd_jcxm:
                if (etTkdYjbz.getText().toString().equals("")) {
                    builde.create().show();
                } else {
                    Intent tojcxm = new Intent(this, ChoiceActivity.class);
                    startActivity(tojcxm);
                    sb.setLength(0);
                }
                break;
            case R.id.et_sjky_jcxm:
                if (etSjkyYjbz.getText().toString().equals("")) {
                    builde.create().show();
                } else {
                    Intent tojcxm = new Intent(this, ChoiceActivity.class);
                    startActivity(tojcxm);
                    sb.setLength(0);
                }
                break;
            case R.id.et_ybsj_jcxm:
                if (etYbsjYjbz.getText().toString().equals("")) {
                    builde.create().show();
                } else {
                    Intent tojcxm = new Intent(this, ChoiceActivity.class);
                    startActivity(tojcxm);
                    sb.setLength(0);
                }
                break;

            case R.id.et_jcxm_wjj:
                Intent tojcxm = new Intent(this, ChoiceActivity.class);
                startActivity(tojcxm);
                sb.setLength(0);
                break;
            case R.id.iv_wtd:
                showDialog2(view, getTakePhoto());
                break;
            case R.id.et_bgfs:
                pvFs.show();
                break;


        }
    }


    //品种分类
    private void initfelei() {
        /**
         * @description
         *
         * 注意事项：
         * 自定义布局中，id为 optionspicker 或者 timepicker 的布局以及其子控件必须要有，否则会报空指针。
         * 具体可参考demo 里面的两个自定义layout布局。
         */

        pvFenLei = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3, View v) {

                String tx = listconcre.get(options1).getName();
                TvJllb.setText(tx);

                switch (listconcre.get(options1).getId()) {
                    case "1":
                        initvisibly();
                        llTkyFather.setVisibility(View.VISIBLE);

                        initclear();
                        break;
                    case "2":
                        initvisibly();
                        llTksFather.setVisibility(View.VISIBLE);

                        initclear();
                        break;
                    case "3":
                        initvisibly();
                        llTkzFather.setVisibility(View.VISIBLE);

                        initclear();
                        break;
                    case "4":
                        initvisibly();
                        llTkdFather.setVisibility(View.VISIBLE);

                        initclear();
                        break;
                    case "5":
                        initvisibly();
                        llSjkyFather.setVisibility(View.VISIBLE);

                        initclear();
                        break;
                    case "6":
                        initvisibly();
                        llYbsjFather.setVisibility(View.VISIBLE);
                        initclear();
                        break;
                    case "7":
                        initvisibly();
                        llWjjFather.setVisibility(View.VISIBLE);
                        initclear();
                        break;
                }


            }
        }).setLayoutRes(R.layout.material_item, new CustomListener() {
            @Override
            public void customLayout(View v) {
                final TextView tvSubmit = (TextView) v.findViewById(R.id.tv_finish);
                TextView ivCancel = (TextView) v.findViewById(R.id.iv_cancel);
                tvSubmit.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        pvFenLei.returnData();
                        pvFenLei.dismiss();

                    }
                });

                ivCancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        pvFenLei.dismiss();
                    }
                });
            }
        })
                .isDialog(false)
                .build();

        pvFenLei.setPicker(name);//添加数据
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void XXX(AddressEventBean messageEvent) {
        if (messageEvent.getId().equals("address")) {
            TvXzdz.setVisibility(View.GONE);
            llYjFather.setVisibility(View.VISIBLE);
            TvXm.setText(messageEvent.getName());
            TvLxdh.setText(messageEvent.getPhone());
            TvYjdz.setText(messageEvent.getAddress());
        }
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void XXl(List<MultipleBean> multiplist) {
        int price = 0;
        for (int i = 0; i < multiplist.size(); i++) {
            sb.append(multiplist.get(i).getName() + ",");
            price += multiplist.get(i).getPrice();
        }
        EtZj.setText("¥" + price);
        if (TvJllb.getText().toString().equals("砼抗压")) {
            etJcxm.setText(sb.toString().substring(0, sb.length() - 1));
        } else if (TvJllb.getText().toString().equals("砼抗渗")) {
            etTksJcxm.setText(sb.toString().substring(0, sb.length() - 1));
        } else if (TvJllb.getText().toString().equals("砼抗折")) {
            etTkzJcxm.setText(sb.toString().substring(0, sb.length() - 1));
        } else if (TvJllb.getText().toString().equals("砼抗冻")) {
            etTkdJcxm.setText(sb.toString().substring(0, sb.length() - 1));
        } else if (TvJllb.getText().toString().equals("砂浆抗压")) {
            etSjkyJcxm.setText(sb.toString().substring(0, sb.length() - 1));
        } else if (TvJllb.getText().toString().equals("预拌砂浆")) {
            etYbsjJcxm.setText(sb.toString().substring(0, sb.length() - 1));
        } else if (TvJllb.getText().toString().equals("外加剂")) {
            etJcxmWjj.setText(sb.toString().substring(0, sb.length() - 1));
        }

    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    private void initclear() {
        etDbsl.setText("");
        etSqcc.setText("");
        etYpmc.setText("");
        tvDj.setText("");
        etYhtj.setText("");
        EtDbsl.setText("");
        etYjbz.setText("");
        etCxrq.setText("");
        etQl.setText("");
        etYqsyrq.setText("");
        etPhblbl.setText("");
        etJcxm.setText("");
        etLysl.setText("");
        etZlzms.setText("");
        etYpcz.setText("");
        EtZj.setText("");
        etTksDbsl.setText("");
        etTksCc.setText("");
        etTksYqsyrq.setText("");
        etTksQddj.setText("");
        etTksKsdj.setText("");
        etTksKddj.setText("");
        etTksYjbz.setText("");
        etTksCxrq.setText("");
        etTksQl.setText("");
        etTksPhbbh.setText("");
        etTksZlzms.setText("");
        etTksLysl.setText("");
        etTksJcxm.setText("");
        etTkzYjbz.setText("");
        etTkzSkcc.setText("");
        etTkzQddj.setText("");
        etTkzDbsl.setText("");
        etTkzYhtj.setText("");
        etTkzCxrq.setText("");
        etTkzQl.setText("");
        etTkzYqsyrq.setText("");
        etTkzZlzms.setText("");
        etTkzLysl.setText("");
        etTkzJcxm.setText("");
        etTkdQddj.setText("");
        etTkdYhtj.setText("");
        etTkdKsdj.setText("");
        etTkdKddj.setText("");
        etTkdCxrq.setText("");
        etTkdQl.setText("");
        etTkdYqsyrq.setText("");
        etTkdPhbbh.setText("");
        etTkdYjbz.setText("");
        etTkdSkcc.setText("");
        etTkdDbsl.setText("");
        etTkdSybh.setText("");
        etTkdLysl.setText("");
        etTkdZlzms.setText("");
        etTkdJcxm.setText("");
        etSjkyYjbz.setText("");
        etSjkySkcc.setText("");
        etSjkyYhtj.setText("");
        etSjkyQddj.setText("");
        etSjkyCxrq.setText("");
        etSjkyQl.setText("");
        etSjkyYqsyrq.setText("");
        etSjkySjzl.setText("");
        etPhblbl.setText("");
        etSjkyZlzms.setText("");
        etSjkyLysl.setText("");
        etSjkyJcxm.setText("");

        etYbsjDbsl.setText("");
        etYbsjScrq.setText("");
        etYbsjSjpz.setText("");
        etYbsjSjzl.setText("");
        etYbsjQddj.setText("");
        etYbsjYjbz.setText("");
        etYbsjSccj.setText("");
        etYbsjZlzs.setText("");
        etYbsjLysl.setText("");
        etYbsjJcxm.setText("");
        etTksZj.setText("");
        etSjkyZj.setText("");
        etTkdZj.setText("");
        etTkzZj.setText("");
        etYbsjZj.setText("");
    }

    private void initvisibly() {
        llTkyFather.setVisibility(View.GONE);
        llTksFather.setVisibility(View.GONE);
        llTkzFather.setVisibility(View.GONE);
        llTkdFather.setVisibility(View.GONE);
        llSjkyFather.setVisibility(View.GONE);
        llYbsjFather.setVisibility(View.GONE);
        llWjjFather.setVisibility(View.GONE);
    }


    //时间选择器
    private void initcxtime() {

        Calendar selectedDate = Calendar.getInstance();
        Calendar startDate = Calendar.getInstance();
        startDate.set(1900, 1, 1);
        Calendar endDate = Calendar.getInstance();
        endDate.set(2100, 1, 1);

        //时间选择器，结束时间
        pvTime1 = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                // 这里回调过来的v,就是show()方法里面所添加的 View 参数，如果show的时候没有添加参数，v则为null

                String time = getTime(date);
                String t = time.substring(0, time.length() - 9);
                TextView tv = (TextView) v;
                tv.setText(t);


            }
        })
                .setType(TimePickerView.Type.YEAR_MONTH_DAY)
                .setLabel("", "", "", "", "", "") //设置空字符串以隐藏单位提示   hide label
                .setDividerColor(Color.DKGRAY)
                .setContentSize(20)
                .setDate(selectedDate)
                .setRangDate(startDate, endDate)
                .build();
    }


    private String getTime(Date date) {//可根据需要自行截取数据显示
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(date);
    }


    /**
     * 选择相册照片或者拍照
     */
    private void showDialog2(View view, final TakePhoto takePhoto) {
        mButtomMenuDialog = new BottomMenuDialog.Builder(this)
                .setShadow(true)
                .addMenu("从手机相册选择", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mButtomMenuDialog.dismiss();
                        selectPhoto(takePhoto);
                    }
                }).addMenu("拍照", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mButtomMenuDialog.dismiss();
                        PHOTO_FILE_NAME = format.format(new Date()) + ".jpg";//指定拍摄图片时 返回的文件名
                        File photo = new File(dir, PHOTO_FILE_NAME);
                        Uri uri = Uri.fromFile(photo);
                        Intent intent2 = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);//拍摄图片
                        intent2.putExtra(MediaStore.Images.Media.ORIENTATION, 0);
                        intent2.putExtra(MediaStore.EXTRA_OUTPUT, uri);
                        startActivityForResult(intent2, 201);
                    }
                }).setCancelListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        mButtomMenuDialog.dismiss();
                    }
                })
                .create();
        mButtomMenuDialog.show();
    }

    /**
     * 选择本地图片的照片
     */
    private void selectPhoto(TakePhoto takePhoto) {
        File file = new File(Environment.getExternalStorageDirectory(), "/temp/" + System.currentTimeMillis() + ".jpg");
        if (!file.getParentFile().exists()) file.getParentFile().mkdirs();
        Uri imageUri = Uri.fromFile(file);
        configCompress(takePhoto);
        configTakePhotoOption(takePhoto);
        takePhoto.onPickMultiple(1);
    }

    private void configCompress(TakePhoto takePhoto) {
        CompressConfig config;
        config = new CompressConfig.Builder()
                .setMaxSize(200 * 1024)
                .create();

        takePhoto.onEnableCompress(config, true);
    }

    private void configTakePhotoOption(TakePhoto takePhoto) {
        TakePhotoOptions.Builder builder = new TakePhotoOptions.Builder();
        builder.setWithOwnGallery(true);
        builder.setCorrectImage(true);
        takePhoto.setTakePhotoOptions(builder.create());

    }


    /**
     * 选择照片、拍摄视频或者拍摄照片的返回结果
     *
     * @param requestCode
     * @param resultCode
     * @param data
     */
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        /**
         * 通过相机拍照并发送
         * */
        if (requestCode == 201) {
            if (resultCode == RESULT_OK) {
                isFirstIn = false;
                File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/PhotoPickTemp/" + PHOTO_FILE_NAME);
                Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);//刷新系统媒体库
                scanIntent.setData(Uri.fromFile(new File(file.getAbsolutePath())));
                sendBroadcast(scanIntent);//发送广播 刷新当前拍摄的图片 添加到系统媒体库
                int angle = BitmapUtils.readPictureDegree(file.getAbsolutePath());
                Bitmap bitmap = BitmapUtils.compressImage(angle, BitmapUtils.decodeUri(ConcreteActivity.this, Uri.fromFile(new File(file.getAbsolutePath())), 720, 1280), file.getAbsolutePath());
                ImageItem takePhoto = new ImageItem();
                takePhoto.setBitmap(bitmap);
                takePhoto.setImagePath(file.getAbsolutePath());
                if (Bimp.tempSelectBitmap.size() > 0)
                    Bimp.tempSelectBitmap.clear();

                Bimp.tempSelectBitmap.add(takePhoto);

                if (Bimp.tempSelectBitmap.size() > 0) {
                    ivWtd.setImageBitmap(Bimp.tempSelectBitmap.get(0).getBitmap());
                } else {
                    ivWtd.setImageResource(R.mipmap.a_dajiahao);
                }
            } else {
                if (isFirstIn) {
                    finish();
                }
            }
        }
    }

    @Override
    public void takeSuccess(TResult result) {
        super.takeSuccess(result);
        isFirstIn = false;
        showImg(result.getImages());
    }

    private void showImg(ArrayList<TImage> images) {
        if (Bimp.tempSelectBitmap.size() > 0)
            Bimp.tempSelectBitmap.clear();
        for (int i = 0; i < images.size(); i++) {
            ImageItem takePhoto = new ImageItem();
            takePhoto.setBitmap(BitmapUtils.decodeUri(ConcreteActivity.this, Uri.fromFile(new File(images.get(i).getCompressPath())), 720, 1280));
            takePhoto.setImagePath(images.get(i).getCompressPath());
            Bimp.tempSelectBitmap.add(takePhoto);
        }
        if (Bimp.tempSelectBitmap.size() > 0) {
            ivWtd.setImageBitmap(Bimp.tempSelectBitmap.get(0).getBitmap());
        } else {
            ivWtd.setImageResource(R.mipmap.a_dajiahao);
        }
    }


    private void Callphone() {
        builde = new JcDialog.Builde(this);
        builde.setCloseListener(new DialogInterface.OnClickListener() {//确定
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                Intent intent = new Intent(Intent.ACTION_CALL);
                Uri data = Uri.parse("tel:" + "02223382753");
                intent.setData(data);
                startActivity(intent);

            }
        });
        builde.setConfireListener(new DialogInterface.OnClickListener() {//取消
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
    }


    private void initfs() {
        pvFs = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3, View v) {

                String tx = list1.get(options1).getName();
                etBgfs.setText(tx);

            }
        }).setLayoutRes(R.layout.material_item, new CustomListener() {
            @Override
            public void customLayout(View v) {
                final TextView tvSubmit = (TextView) v.findViewById(R.id.tv_finish);
                TextView ivCancel = (TextView) v.findViewById(R.id.iv_cancel);
                tvSubmit.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        pvFs.returnData();
                        pvFs.dismiss();

                    }
                });

                ivCancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        pvFs.dismiss();
                    }
                });
            }
        })
                .isDialog(false)
                .build();

        pvFs.setPicker(lvname);//添加数据
    }

}

